package com.study.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

public class FoodOperator {
    ArrayList<Food> foods = new ArrayList<>();
    Scanner scanner = new Scanner(System.in);

    private void addFood() {
        System.out.println("===========上架菜品============");
        Food food = new Food();
        System.out.println("菜品名称:");
        String name = scanner.next();
        System.out.println("菜品价格:");
        double price = scanner.nextDouble();
        System.out.println("菜品描述:");
        String desc = scanner.next();
        food.setName(name);
        food.setPrice(price);
        food.setDesc(desc);
        foods.add(food);
        System.out.println("菜品上架成功");
    }
    private void showAllFoods() {
        System.out.println("===========全部菜品============");
        for (int i = 0; i < foods.size(); i++) {
            Food food = foods.get(i);
            System.out.println(food.getName()+","+food.getPrice()+","
                                +food.getDesc());
        }

    }
    private void delFood() {
        System.out.println("请输入要删除的菜品编号(阿拉伯数字):");
        int i = scanner.nextInt();
        foods.remove(i);
        System.out.println("菜品已删除");
    }

    public void start() {
        while (true) {
            System.out.println("===========商家管理系统============");
            System.out.println("1、上架菜品");
            System.out.println("2、下架菜品");
            System.out.println("3、展示菜品");
            System.out.println("请输入数字");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    addFood();
                    break;
                case 2:
                    delFood();
                    break;
                case 3:
                    showAllFoods();
                    break;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }
    }



}
